<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>首页</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/layui/2.11.2/css/layui.min.css" rel="stylesheet">
    <style>
        .sousuo {
            margin-left: 20px;
            position: relative;
        }

        .sousuo>img {
            width: 20px;
            height: 20px;
            position: absolute;
            top: 20px;
            left: 3px;
            border-radius: 5px 0 0 5px;
        }

        #sou {
            width: 900px;
            height: 25px;
            border-radius: 50px;
            box-sizing: border-box;
            padding-left: 25px;
            border: 0;
        }

        .layui-side-scroll {
            background-color: #003f70;
        }

        .layui-nav-tree {
            background-color: #003f70;
        }

        #layui-header {
            background-color: #003f70;
        }
    </style>
</head>

<body>
    <div class="layui-layout layui-layout-admin">
        <div class="layui-header" id="layui-header">
            <div class="layui-logo layui-hide-xs layui-bg-black" id="layui-bg-black">管理系统</div>
            <!-- 头部区域（可配合layui 已有的水平导航） -->
            <ul class="layui-nav layui-layout-left">
                <!-- 移动端显示 -->
                <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" lay-header-event="menuLeft">
                    <i class="layui-icon layui-icon-spread-left"></i>
                </li>
                <!-- <li class="layui-nav-item layui-hide-xs"><a href="javascript:;">nav 1</a></li>
                <li class="layui-nav-item layui-hide-xs"><a href="javascript:;">nav 2</a></li>
                <li class="layui-nav-item layui-hide-xs"><a href="javascript:;">nav 3</a></li> -->
                <!-- 搜索 -->
                <li class="layui-nav-item">
                    <div class="sousuo">
                        <img src="https://ts1.tc.mm.bing.net/th/id/OIP-C.lpddQ7iAtQBY3ans1P7oVgHaHa?w=201&h=211&c=8&rs=1&qlt=90&o=6&dpr=1.3&pid=3.1&rm=2"
                            alt="">
                        <input type="text" name="" id="sou" placeholder="请输入内容">
                    </div>
                </li>
            </ul>
            <ul class="layui-nav layui-layout-right">
                <li class="layui-nav-item layui-hide layui-show-sm-inline-block">
                    <a href="javascript:;">
                        <!-- 头像 -->
                        <img src="//unpkg.com/outeres@0.0.10/img/layui/icon-v2.png" class="layui-nav-img">
                        <span class="yhname">1</span>
                    </a>
                    <!-- 头像旁边的下拉列表 -->
                    <dl class="layui-nav-child">
                        <dd> <a href="./个人资料.html">个人资料</a></dd>
                        <dd><a href="./商品列表.html">商品列表</a></dd>
                    </dl>
                </li>
            </ul>
        </div>
        <div class="layui-side layui-bg-black">
            <div class="layui-side-scroll">
                <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
                <ul class="layui-nav layui-nav-tree" lay-filter="test">
                    <li class="layui-nav-item layui-nav-itemed">
                        <a class="" href="./首页.html" id="yi">商品数据</a>
                    </li>
                    <li class="layui-nav-item">
                        <a href="./商品列表.html">商品管理列表</a>
                    </li>
                    <li class="layui-nav-item">
                        <a href="./个人资料.html">个人资料</a>
                    </li>
                    <li class="layui-nav-item">
                        <a href="./商品详情.html">商品详情</a>
                    </li>
                </ul>
            </div>
        </div>
        <div class="layui-body">
            <!-- 内容主体区域 -->
            <div style="padding: 15px;">
                <blockquote class="layui-elem-quote layui-text">
                    数据图表
                </blockquote>
                <div class="layui-card layui-panel">
                    <div id="main" style="width: 100%;height:400px; border: 1px solid;"></div>
                    <div id="main1"
                        style="width: 400px;height:400px; margin-top: 20px; border: 1px solid; display: inline-block;">
                    </div>
                    <div id="main2"
                        style="width: 800px;height:400px; margin-top: 20px; border: 1px solid; display: inline-block;position: absolute;right: 0;">
                    </div>
                </div>
            </div>
        </div>
        <!-- <div class="layui-footer">
            底部固定区域
        </div> -->
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/layui/2.11.2/layui.min.js"></script>
    <script src="https://code.jquery.com/jquery-3.7.1.js"></script>
    <script src=" https://cdn.jsdelivr.net/npm/echarts@5.6.0/dist/echarts.min.js "></script>
    <script type="text/javascript">
        $('document').ready(() => {
            $('#yi').css('background', '#16baaa')

        })
        //JS 
        layui.use(['element', 'layer', 'util'], function () {
            var element = layui.element;
            var layer = layui.layer;
            var util = layui.util;
            var $ = layui.$;

            //头部事件
            util.event('lay-header-event', {
                menuLeft: function (othis) { // 左侧菜单事件
                    layer.msg('展开左侧菜单的操作', { icon: 0 });
                },
            });
        });
        //用户名
        var shu = JSON.parse(localStorage.getItem('1'))
        $('.yhname').html(shu.name)
        //跳转
        function goods_list() {
            location.assign('./商品列表.html')
        }
        var yx = JSON.parse(localStorage.getItem('geren'))
        //头像
        $('.layui-nav-img')[0].src = `${yx.img}`
        //数据图表
        var myChart = echarts.init(document.getElementById('main'));
        var myChart1 = echarts.init(document.getElementById('main1'));
        var myChart2 = echarts.init(document.getElementById('main2'));
        $.ajax({
            type: "GET",
            url: 'https://liu.zzgoodqc.cn/goodsx/sort',
            data: {
                sort: 'desc',
                type: "price",
                page: `1`,
                limit: '5',
            },
            dataType: "json",
            success: (a) => {
                var shu = a.data
                const colors = ['#5470C6', '#EE6666'];
                var a1 = []
                var b1 = []
                var c1 = []
                var d1 = []
                shu.forEach(item => {
                    var a = item.price
                    var b = item.stock
                    var c = item.goods_name
                    var d = item.sold
                    a1.push(a)
                    b1.push(b)
                    c1.push(c)
                    d1.push(d)
                    //线性数据
                    option = {
                        title: {
                            text: '价格库存对比',
                            left: 'left'
                        },
                        color: colors,
                        tooltip: {
                            trigger: 'none',
                            axisPointer: {
                                type: 'cross'
                            }
                        },
                        legend: {},
                        grid: {
                            top: 70,
                            bottom: 50
                        },
                        xAxis: [
                            {
                                type: 'category',
                                axisTick: {
                                    alignWithLabel: true
                                },
                                axisLine: {
                                    onZero: false,
                                    lineStyle: {
                                        color: colors[1]
                                    }
                                },
                                axisPointer: {
                                    label: {
                                        formatter: function (params) {
                                            return (
                                                '商品名称  ' +
                                                params.value +
                                                (params.seriesData.length ? '：' + params.seriesData[0].data : '')
                                            );
                                        }
                                    }
                                },
                                // prettier-ignore
                                data: c1
                            },
                            {
                                type: 'category',
                                axisTick: {
                                    alignWithLabel: true
                                },
                                axisLine: {
                                    onZero: false,
                                    lineStyle: {
                                        color: colors[0]
                                    }
                                },
                                axisPointer: {
                                    label: {
                                        formatter: function (params) {
                                            return (
                                                '商品名称  ' +
                                                params.value +
                                                (params.seriesData.length ? '：' + params.seriesData[0].data : '')
                                            );
                                        }
                                    }
                                },
                                // prettier-ignore
                                data: c1
                            }
                        ],
                        yAxis: [
                            {
                                type: 'value'
                            }
                        ],
                        series: [
                            {
                                name: '价格',
                                type: 'line',
                                xAxisIndex: 1,
                                smooth: true,
                                emphasis: {
                                    focus: 'series'
                                },
                                data: a1
                            },
                            {
                                name: '库存 ',
                                type: 'line',
                                smooth: true,
                                emphasis: {
                                    focus: 'series'
                                },
                                data: b1
                            }
                        ]
                    };
                    //饼状图
                    option1 = {
                        title: {
                            text: '已售（前5）',
                            left: 'center'
                        },
                        tooltip: {
                            trigger: 'item'
                        },
                        legend: {
                            orient: 'vertical',
                            left: 'left'
                        },
                        series: [
                            {
                                name: c1,
                                type: 'pie',
                                radius: '50%',
                                top: '20%',
                                data: [
                                    { value: d1[0], name: c1[0] },
                                    { value: d1[1], name: c1[1] },
                                    { value: d1[2], name: c1[2] },
                                    { value: d1[3], name: c1[3] },
                                    { value: d1[4], name: c1[4] }
                                ],
                                emphasis: {
                                    itemStyle: {
                                        shadowBlur: 10,
                                        shadowOffsetX: 0,
                                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                                    }
                                }
                            }
                        ]
                    };
                    //柱状图
                    option2 = {
                        title: {
                            text: '对比图',
                            left: 'left'
                        },
                        tooltip: {
                            trigger: 'axis',
                            axisPointer: {
                                type: 'shadow'
                            }
                        },
                        grid: {
                            left: '3%',
                            right: '4%',
                            bottom: '3%',
                            containLabel: true
                        },
                        xAxis: [
                            {
                                type: 'category',
                                data: c1,
                                axisTick: {
                                    alignWithLabel: true
                                }
                            }
                        ],
                        yAxis: [
                            {
                                type: 'value'
                            }
                        ],
                        series: [
                            {
                                name: '价格',
                                type: 'bar',
                                barWidth: '20%',
                                data: a1
                            },
                            {
                                name: '库存',
                                type: 'bar',
                                barWidth: '20%',
                                data: b1
                            },
                            {
                                name: '销量',
                                type: 'bar',
                                barWidth: '20%',
                                data: d1
                            }


                        ]
                    };
                });
                myChart.setOption(option);
                myChart1.setOption(option1);
                myChart2.setOption(option2);
            },
            error: (e) => {
                console.log(e);
            }
        })
    </script>
</body>

</html>